<?php
/**
 * Search for an existing survey - Interface
 * 
 * 
 */
use Fox\Generator;

use Fox\Grid\FieldCat\Field\Renderer\Anchor;
use Fox\Html\Input;
use Fox\Dao\SqlFragment;
use Nawa\Survey;
use Fox\Html\Block;
use Fox\Html\Screen;

//@TODO add authorization check

$screen = new Screen('sSearch','search');
$screen->pageTitle(Msg(Nawa\Messages::BUNDLE,Nawa\Messages::SURVEYS_LIST));
// Bl
$block = new Block('bSearch',Msg(Fox\Msg::BUNDLE,Fox\Msg::MSG_SEARCH_CRITERIA));
$block->add(new Input(array('survey_label','label')))
		->useLike();
$screen->add($block);

if($screen->submitted()) {
	$fields = $screen->get();
	if(!$screen->errors()) {
		$fragments = $screen->fragments();
		$finder = new Survey();
		$result = $finder->find(SqlFragment::combine($fragments));
		
		// Result Grid
		$grid = new Fox\Grid('gResult');
		$grid->fieldcat(array(array('survey_label','label'),'uname','udate'));
		$grid->fieldcat()->switchToObjectMode();
		$grid->onClick(Generator::location(Generator::url('survey','update',null,array(
			'surveyid' => Generator::useAttribute('surveyid')
		))));
		$grid->initialize($result);
	}
}
echo $screen->display();
if(isset($grid)) {
	echo $grid->display();
}